
#pragma once
#include "VMPI_Lock.h"

class CLinkedNode
{
public:
	CLinkedNode() :pNext(nullptr) {}
	virtual ~CLinkedNode() {}
	__forceinline CLinkedNode *getNext() const { return pNext; }
	__forceinline void setNext(CLinkedNode *p) { pNext = p; }
protected:
	CLinkedNode *pNext;
};

class CLinkedList
{
public:
	CLinkedList();
	virtual ~CLinkedList();
	void clear();
	bool IsEmpty() const { return m_first == nullptr; };
	bool AddNode(CLinkedNode *pAdd);
	bool AddNodeAtFirst(CLinkedNode *pAdd);
	virtual CLinkedNode *GetNode();
	__forceinline CLinkedNode *GetFirstNode() const { return m_first; }
	void RemoveNode(CLinkedNode *pNode, CLinkedNode *pPrevNode = nullptr);
protected:
	void AddLastNode(CLinkedNode *pAdd);
	void RemoveFirstNode();

	vmpi_spin_lock lock_node;
	CLinkedNode *m_first, *m_last;
};
